var UI = {
	base: function() { //初始JS集
		var to_size = function() { //页面左右界面对齐
			var l_h = $('.left').height(),
				r_h = $("body").height(),
				sh = window.screen.height - 160,
				mhei;
			mhei = l_h > r_h ? 'auto' : r_h;
			if(mhei != "auto") {
				mhei = mhei > sh ? mhei : sh;
			}
			$('.left').css('height', mhei);
		}

		var query_input = function() { //自定义表单组件优化
			var mz = [{
				type: 'input[type="radio"]',
				clas: 'ui_r_id',
				tpl: function(i) {
					return '<span class="ui_radio ui_r_id' + i + '"></span>';
				}
			}, {
				type: 'input[type="checkbox"]',
				clas: 'ui_c_id',
				tpl: function() {
					return '<span class="ui_checkbox"></span>';
				}
			}, {
				type: 'select',
				clas: 'ui_s_id',
				tpl: function(i, s, op) {
					return '<div class="ui_select ui_s_id' + i + '"><span class="ui_s_t">' + s + '</span><div class="ui_s_bk">' + op + '</div></div>';
				}
			}];

			for(var i = 0; i < mz.length; i++) {
				var dom = mz[i];
				$(dom.type).not('.disn').each(function(i) {
					var _ = $(this),
						adclas = '';

					if(dom.type === "select") {
						if(_.hasClass('nodis')) {
							return false;
						}
						_.addClass('C_' + dom.clas + i + ' disn').hide();
						var op = _.find('option'),
							mstr = [];
						op.each(function() {
							mstr.push($(this).text());
						});
						//123
						_.after(dom.tpl(i, mstr[0], '<a href="javascript:void(0)">' + mstr.join('</a><a href="javascript:void(0)">') + "</a>"));
						mstr = null;
						var new_dom = $('.' + dom.clas + i);
						new_dom.find('.ui_s_t').click(function() {
							new_dom.find('.ui_s_bk').slideToggle(200, "easeInSine");
						});
						new_dom.css('z-index', 99 - i);
						new_dom.find('.ui_s_bk a').click(function() {
							$(this).addClass('cur').siblings().removeClass('cur');
							new_dom.find('.ui_s_t').text($(this).text());

							new_dom.find('.ui_s_bk').slideToggle(200, "easeInSine");
							op.eq($(this).index()).attr('selected', true);
						});
						new_dom.find('.ui_s_bk').mouseleave(function() {
							new_dom.find('.ui_s_bk').stop(false, true).slideUp(200, "easeInSine");
						});

					} else if(dom.type === 'input[type="checkbox"]') {
						_.addClass('disn').hide();
						_.after(dom.tpl());
						adclas = _.is(":checked") ? "checked" : '';
						var new_dom = _.next('.ui_checkbox');
						new_dom.addClass(adclas);

						new_dom.click(function() {
							if(_.is(":checked")) {
								$(this).removeClass('checked');
								_.removeAttr('checked');
							} else {
								$(this).addClass('checked');
								_.attr('checked', 'checked');
							}
						});
					} else if(dom.type === 'input[type="radio"]') {
						_.addClass('C_' + dom.clas + i + ' disn').hide();
						_.after(dom.tpl(i));
						var new_dom = $('.' + dom.clas + i),
							new_adclas = "radio_" + _.attr('name');
						adclas = _.is(":checked") ? "checked" : '';
						new_dom.addClass(adclas + " " + new_adclas);
						new_dom.attr('data-val', _.val());
						$('.' + new_adclas).click(function() {
							$('.' + new_adclas).removeClass('checked');
							$(this).addClass('checked');
							$('input[name="as"][type="radio"]').val($(this).attr('data-val'))
						});
					}
				})
			}
			//console.log('end query_input')
		}();

		to_size();
		$(window).resize(function() {
			to_size();
		});

		return this;
	},
	log: function(s) { //提示窗
		var r = confirm(s);
		//r==true?alert('确定'):alert('取消');
		return r;
	},

	//  以下注释不在本项目范围内
	//	home: function(strs) { //首页JS集
	//
	//		$('.down_').toggle(function() { //待办事务
	//			var li = $('.hot_news li'),
	//				w = li.length * (li.height() + 1) + 10;
	//			$('.hot_news').animate({
	//				'height': w
	//			}, 350, 'easeInSine')
	//		}, function() {
	//			$('.hot_news').animate({
	//				'height': 170
	//			}, 250, 'easeOutSine')
	//		});
	//
	//		var $a = $('#show_btn'),
	//			$b = $('#edit_btn'),
	//			that = this,
	//			$add;
	//
	//		//初始加载
	//		$a.append(strs);
	//		$add = $a.find('.addli');
	//
	//		//添加事件
	//		$a.find('.addli').click(function() {
	//			alert('添加');
	//		});
	//
	//		//编辑事件
	//		$b.toggle(function() {
	//			$(this).addClass('yellow').text('取消编辑');
	//			$add.show();
	//			$a.find('.close').show();
	//		}, function() {
	//			$(this).removeClass('yellow').text('编辑');
	//			$add.hide();
	//			$a.find('.close').hide();
	//		});
	//
	//		//删除
	//		$a.find('.close').on('click', function() {
	//			var flat = that.log('确定是否删除！');
	//			if (flat) {
	//				$(this).parents('li').remove();
	//			};
	//		});
	//
	//		return this;
	//	},

	message: function() {
		var Wh = $(window).height();
		var $a = $('.up_btn'),
			$b = $('.dn_btn'),
			$c = $('.nav_'),
			cul,
			falt = false,
			Qh = 0;

		if(Wh - 100 > 800) {
			Qh = 660;
		} else {
			Qh = Wh - 100;
		}
		$c.css('height', Qh);
		var setSt = function(num) {
			if(!falt) {
				$c.animate({
					'scrollTop': num
				}, 120, 'easeOutSine', function() {
					falt = false;
				});
			}
		};

		$c.live('mousewheel', function(e) {

			e = e || window.event;
			if(e && e.preventDefault) {
				e.preventDefault();
				e.stopPropagation();
			} else {
				e.returnvalue = false;

				return false;
			}

			var w_b = $('.nav_').height(),
				n_b = $('.nav_ ul').height(),
				t_h = 170,
				num = 0;
			var pi = e.deltaY * -1;
			if(t_h > 0) {

				num = $(this).scrollTop() + t_h * pi;
				setSt(num);
				falt = true;
			}
		});

		$b.click(function() {
			var w_b = $('.nav_').height(),
				n_b = $('.nav_ ul').height(),
				t_h = 55,
				num = 0;
			if(t_h > 0) {
				num = $c.scrollTop() + t_h;
				setSt(num);
				falt = true;
			}
		});
		$a.click(function() {
			var w_b = $('.nav_').height(),
				n_b = $('.nav_ ul').height(),
				t_h = 55,
				num = 0;

			if(t_h > 0) {
				num = $c.scrollTop() - t_h;
				setSt(num);
				falt = true;
			}
		});

		/*$c.find('.it_a').click(function(){ 
				console.log(123)
				$(this).siblings('ol').slideToggle();
                $(this).parent('.item').toggleClass('cur');
			});
			$c.find('.cur ol').slideDown();*/

		return this;
	},
	getTimes: function() {
		var a = new Date(),
			y = a.getFullYear(),
			m = a.getMonth() + 1,
			d = a.getDate(),
			hour = a.getHours(),
			minu = a.getMinutes(),
			seco = a.getSeconds();
		m = m <= 9 ? '0' + m : m;
		d = d <= 9 ? '0' + d : d;
		hour = hour <= 9 ? '0' + hour : hour;
		minu = minu <= 9 ? '0' + minu : minu;
		seco = seco <= 9 ? '0' + seco : seco;
		return {
			ymd: y + "-" + m + '-' + d,
			ymds: y + "-" + m + '-' + (d - 1),
			start_ymd_hms:y + "-" + m + '-' + d + " " + "00:00:00",
			end_ymd_hms: y + "-" + m + '-' + d + " " + hour + ":" + minu + ":" + seco,
			times: function(t) {
				t = t || this.ymd;
				t = t.replace(/-/g, '/');
				return new Date(t).getTime() / 1000;
			}
		}
	},
	getParameterByName: function(name) {
		var match = RegExp('[?&]' + name + '=([^&]*)')
			.exec(window.location.search);
		return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
	}
};

//初始设置时间 墨绿UI
if(typeof(laydate) === "function") {
	laydate.skin('molv');
}
//
if(typeof(callPback) !== 'function') {
	function callPback(tmp) {
		var Maxh = $(window).height() * 0.9;
		$.layer({
			type: 1, //0-4的选择,
			title: false,
			maxmin: false,
			shadeClose: true,
			area: [$(window).width() * 0.9, Maxh],
			page: {
				html: '<div style="overflow-x:hidden;  overflow-y: scroll; height:' + Maxh + 'px">' + tmp + '</div>'
			}
		});
	}
}

var log = function(s) {
	if(typeof(console.log) === "function") {
		var t = typeof(s);
		if(t === 'string') {
			console.log('form log:' + s);
		} else if(t === 'object') {
			console.log(s);
		}
	}
}

function gecheck(datas, prid, str) {
	var i = 0,
		len = datas.children.length;
	var getS = function(str, ptid) {
		var strs = '';
		for(; i < len; i++) {
			if(datas.children[i]['id'] == ptid) {
				strs = ' > <a href="../' + datas.children[i]['menuUrl'] + '?parId=' + datas.children[i]['id'] + '">' + datas.children[i]['name'] + '</a>';
			}
		}
		$('.path_').append(strs + str);
		//console.log(ptid)
	}
	for(; i < len; i++) {

		var mdata = datas.children[i].children;
		for(var ii = 0; ii < mdata.length; ii++) {
			if(mdata[ii]['id'] == prid) {
				str = ' > <a href="../' + mdata[ii]['menuUrl'] + '?parId=' + mdata[ii]['id'] + '">' + mdata[ii]['name'] + '</a>';
				getS(str, mdata[ii]['parentMenuId']);
			}
		}
	}
}